package com.item.daoEx.model;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

import com.item.dao.model.Book;
import com.item.service.BookService.BookCategory;

public class BookEx extends Book {
	private List<BookCategory> ctCodeList = new ArrayList<BookCategory>();
	private Integer isInCart = 0;
	private Integer oCount = 0;

	public BookEx() {
		super();
	}
	
	public BookEx(Book book) {
		if(book != null) {
			this.setName(book.getName());
			this.setCreateTime(book.getCreateTime());
			this.setModifyTime(book.getModifyTime());
			this.setAuthor(book.getAuthor());
			this.setCreateTime(book.getCreateTime());
			this.setCtCode(book.getCtCode());
			this.setDescription(book.getDescription());
			this.setDirectory(book.getDirectory());
			this.setId(book.getId());
			this.setImg(book.getImg());
			this.setIsbn(book.getIsbn());
			this.setIsHot(book.getIsHot());
			this.setRate(book.getRate());
			this.setReportory(book.getReportory());
			this.setPriceOriginal(book.getPriceOriginal());
			this.setPriceSelling(book.getPriceSelling());
			this.setPublisher(book.getPublisher());
			this.setTimePublish(book.getTimePublish());
			this.setVersion(book.getVersion());
			this.setBooksize(book.getBooksize());
			this.setWordcount(book.getWordcount());
			this.setPack(book.getPack());
			this.setPagecount(book.getPagecount());
			this.setPaper(book.getPaper());
			this.setPrintDate(book.getPrintDate());
			this.setPrintTime(book.getPrintTime());
			this.setVersion(book.getVersion());
		}
	}
	
	//类别码模式
	private static Pattern ctP = Pattern.compile("(S\\d{2})(D\\d{2})(M\\d{2})(T\\d{2})(C\\d{2})(Y\\d{2})?");
	/**
	 * 解析出类型列表
	 */
	public void setCtCodes() {
		String ctCodes = this.getCtCode();
		if(StringUtils.isNotBlank(ctCodes)) {
			Matcher ctM = ctP.matcher(ctCodes);
			while(ctM.find()) {
				BookCategory bc = new BookCategory();
				bc.setSchoolCode(ctM.group(1));
				bc.setDepartmentCode(ctM.group(2));
				bc.setMajorCode(ctM.group(3));
				bc.setTypeCode(ctM.group(4));
				bc.setCategoryCode(ctM.group(5));
				if(ctM.group(6) != null)
					bc.setYearCode(ctM.group(6));
				ctCodeList.add(bc);
			}
		}
	}

	public List<BookCategory> getCtCodeList() {
		return ctCodeList;
	}

	public void setCtCodeList(List<BookCategory> ctCodeList) {
		this.ctCodeList = ctCodeList;
	}

	public Integer getIsInCart() {
		return isInCart;
	}

	public void setIsInCart(Integer isInCart) {
		this.isInCart = isInCart;
	}

	public Integer getoCount() {
		return oCount;
	}

	public void setoCount(Integer oCount) {
		this.oCount = oCount;
	}

}
